//
//  BHNavigationController.m
//  PropertyMananger
//
//  Created by bh on 16/12/20.
//  Copyright © 2016年 BH. All rights reserved.
//

#import "BHNavigationController.h"

@interface BHNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation BHNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    self.interactivePopGestureRecognizer.delegate = self;
   
    // 设置导航栏背景颜色
    self.navigationBar.barTintColor = Theme_Color;
    self.view.backgroundColor = [UIColor whiteColor];
      
    //禁止 navigationBar 和 tabBar 为半透明
    self.navigationController.navigationBar.translucent = NO;
    self.tabBarController.tabBar.translucent = NO;
    
    [self.navigationController.navigationBar setTitleTextAttributes:
     
  @{NSFontAttributeName:[UIFont systemFontOfSize:18],
    
    NSForegroundColorAttributeName:[UIColor whiteColor]}];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    // 如果不是第一个push进来的子控制器，需要设置返回键
    if (self.childViewControllers.count > 0) {
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        
        
        [backButton setImage:[UIImage imageNamed:@"ico_return"] forState:UIControlStateNormal];
        
        [backButton sizeToFit];
        [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
        viewController.hidesBottomBarWhenPushed = YES; // 当push的时候隐藏底部的tabbar
    }
    
    [super pushViewController:viewController animated:animated];
}

#pragma mark - 监听
- (void)back
{
    [self popViewControllerAnimated:YES];
    
    
}

#pragma mark - <UIGestureRecognizerDelegate>
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    // 手势何时有效：当子控制器的个数 > 1
    return self.childViewControllers.count > 1;
}


@end
